package com.ohuang.wallpapermanager.compose

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Button
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.sp

@Composable
fun SpinnerDropdown(
    modifier: Modifier = Modifier,
    items: List<String>,
    onItemSelected: (Int, String) -> Unit,
    content: @Composable () -> Unit
) {
    val state = remember {
        mutableStateOf(false)
    }
    Box(modifier = modifier.clickable {
        state.value = true
    }) {
        content()
    }
    DropdownMenu(
        expanded = state.value,
        onDismissRequest = {
            state.value = false
        },
        modifier = Modifier.fillMaxWidth()
    ) {
        items.forEachIndexed { index, item ->
            DropdownMenuItem(
                onClick = {
                    state.value = false
                    onItemSelected(index, item)
                },
                text = {
                    Text(
                        text = item,
                        style = TextStyle(fontSize = 16.sp)
                    )
                }
            )
        }
    }
}